package homeword;

import java.util.Random;

//获取一个随机验证码，前4个为字母后一位为数字
public class CAPTCHA {
    public static void main(String[] args) {
        //创建数组存放字母
        char[] chs = new char[52];
        for (int i = 0; i < chs.length; i++) {
            //存储字母a——z在26个数组里面
            if (i <= 25) {
                chs[i] = (char) (97 + i);
            } else {//将25个大写字母填进去
                chs[i] = (char) (65 + i - 26);
            }
        }
        //随机抽取4个字母
        Random random = new Random();

        //记录最终的拼接结果
        String result = "";
        for (int i = 0; i < 4; i++) {
            int resultIndxe = random.nextInt(chs.length);
            result = result + chs[resultIndxe];
        }
        //抽取最后一个数字进行拼接
        int number = random.nextInt(9);
        result = result + number;
        System.out.println(result);

    }

}
